package com.firefly.service.repository.ums;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.ums.po.RoleAdminPo;
import com.firefly.dao.dao.ums.service.RoleAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 角色下用户
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/5
 **/
@Repository
public class RoleAdminRepository {
    private final RoleAdminService roleAdminService;
    @Autowired
    public RoleAdminRepository(RoleAdminService roleAdminService){
        this.roleAdminService = roleAdminService;
    }
    public Boolean removeAdminByRoleId(int roleId,int adminId){
        QueryWrapper<RoleAdminPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId).eq("admin_id", adminId);
        return roleAdminService.remove(queryWrapper);
    }
    public void saveBatchByAdminId(int adminId, List<Integer> roleIds){
        List<RoleAdminPo> inserts = new ArrayList<>();
        roleIds.forEach(item -> {
            RoleAdminPo tmp = new RoleAdminPo();
            tmp.setRoleId(item);
            tmp.setAdminId(adminId);
            inserts.add(tmp);
        });
        roleAdminService.saveBatch(inserts);
    }
    public void removeByAdminId(int adminId){
        QueryWrapper<RoleAdminPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("admin_id", adminId);
        roleAdminService.remove(queryWrapper);
    }
    public void removeByAdminIds(List<Integer> adminIds){
        QueryWrapper<RoleAdminPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("admin_id", adminIds);
        roleAdminService.remove(queryWrapper);
    }
}
